/* global $ setBtnClickFuc genTestUserSig */

// preset before starting RTC
class Presetting {
    init() {
        // populate userId/roomId
        //$('#userId').val('user_' + parseInt(Math.random() * 100000000));
        // $('#roomId').val(parseInt(Math.random() * 100000));
        const array  = this.query('roomId').split("_");
        const roomId = array[0] ;
        const userId = array[1] ;
        if (roomId) {
            $('#roomId').val(roomId);
        }
        if (userId) {
            $('#userId').val(userId);
        }

        $('#main-video-btns').hide();
        $('.mask').hide();
        setBtnClickFuc();
    }

    query(name) {
        const match = window.location.search.match(new RegExp('(\\?|&)' + name + '=([^&]*)(&|$)'));
        return !match ? '' : decodeURIComponent(match[2]);
    }

    login(share, callback) {
        let userId = $('#userId').val();
        if (share) {
            userId = 'share_' + userId;
        }
        const roomId = $('#roomId').val();
        $.ajax({
            async: false,
            type: "get",
            url: "https://xxgzc.aesd.cn/banzheng/getUserSig",
            data: {'userId': userId},
            dataType: 'json',
            success: function (data) {
                const sdkAppId = data.data.sdkAppId;
                const userSig = data.data.userSig;
                callback({
                    sdkAppId,
                    userId,
                    userSig,
                    roomId
                });
                console.log("获取登录信息", {'sdkAppId':sdkAppId,'userSig':userSig});
            }
        });

    }
}
